By rubensans on
Hello,
I have 5 block with the next code that give me 5 dropdown menus.
Anyone knows how I can joint them to put them on a only block that shows me the 5 dropdown menus?
Thanks.
Block 1:
$output = drupal_get_form('Coches_dropdown_form', $form);
return $output;
function Coches_dropdown_form() {
$vid=5;
$formname="Coches - TodoTerrenos";
$vocabulary = db_query("SELECT td.name, td.tid FROM {term_data} td WHERE td.vid=%d ORDER BY td.name", $vid);
// Initialise the country array
$options[] = t('' . $formname);
//Populate array with url / name
while ($term = db_fetch_object($vocabulary)) {
$options[url("taxonomy/term/$term->tid")] = $term->name;
}
//Build dropdown select
//If we try to build OnChange directly it gets mangled, so put in array to confuse the forms api
$form['category'] = array(
'#type' => 'select',
'#name' => $formname,
'#id' => $formname,
'#title' => '',
'#default_value' => '',
'#options' => $options,
'#description' => '',
'#multiple' => $multiple = FALSE,
'#required' => $required = FALSE,
'#attributes' => array('onChange' => "top.location.href=document.getElementById('$formname').options[document.getElementById('$formname').selectedIndex].value"),
);
return $form;
}
Block2:
$output = drupal_get_form('LCV_dropdown_form', $form);
return $output;
function LCV_dropdown_form() {
$vid=9;
$formname="Furgonetas - Comerciales";
$vocabulary = db_query("SELECT td.name, td.tid FROM {term_data} td WHERE td.vid=%d ORDER BY td.name", $vid);
// Initialise the country array
$options[] = t('' . $formname);
//Populate array with url / name
while ($term = db_fetch_object($vocabulary)) {
$options[url("taxonomy/term/$term->tid")] = $term->name;
}
//Build dropdown select
//If we try to build OnChange directly it gets mangled, so put in array to confuse the forms api
$form['category'] = array(
'#type' => 'select',
'#name' => $formname,
'#id' => $formname,
'#title' => '',
'#default_value' => '',
'#options' => $options,
'#description' => '',
'#multiple' => $multiple = FALSE,
'#required' => $required = FALSE,
'#attributes' => array('onChange' => "top.location.href=document.getElementById('$formname').options[document.getElementById('$formname').selectedIndex].value"),
);
return $form;
}
Block 3:
$output = drupal_get_form('Camiones_Tractores_dropdown_form', $form);
return $output;
function Camiones_Tractores_dropdown_form() {
$vid=6;
$formname="Camiones / Tractores";
$vocabulary = db_query("SELECT td.name, td.tid FROM {term_data} td WHERE td.vid=%d ORDER BY td.name", $vid);
// Initialise the country array
$options[] = t('' . $formname);
//Populate array with url / name
while ($term = db_fetch_object($vocabulary)) {
$options[url("taxonomy/term/$term->tid")] = $term->name;
}
//Build dropdown select
//If we try to build OnChange directly it gets mangled, so put in array to confuse the forms api
$form['category'] = array(
'#type' => 'select',
'#name' => $formname,
'#id' => $formname,
'#title' => '',
'#default_value' => '',
'#options' => $options,
'#description' => '',
'#multiple' => $multiple = FALSE,
'#required' => $required = FALSE,
'#attributes' => array('onChange' => "top.location.href=document.getElementById('$formname').options[document.getElementById('$formname').selectedIndex].value"),
);
return $form;
}
Block 4:
$output = drupal_get_form('Barcos_dropdown_form', $form);
return $output;
function Barcos_dropdown_form() {
$vid=8;
$formname="Barcos / Veleros";
$vocabulary = db_query("SELECT td.name, td.tid FROM {term_data} td WHERE td.vid=%d ORDER BY td.name", $vid);
// Initialise the country array
$options[] = t('' . $formname);
//Populate array with url / name
while ($term = db_fetch_object($vocabulary)) {
$options[url("taxonomy/term/$term->tid")] = $term->name;
}
//Build dropdown select
//If we try to build OnChange directly it gets mangled, so put in array to confuse the forms api
$form['category'] = array(
'#type' => 'select',
'#name' => $formname,
'#id' => $formname,
'#title' => '',
'#default_value' => '',
'#options' => $options,
'#description' => '',
'#multiple' => $multiple = FALSE,
'#required' => $required = FALSE,
'#attributes' => array('onChange' => "top.location.href=document.getElementById('$formname').options[document.getElementById('$formname').selectedIndex].value"),
);
return $form;
}
Block 5:
$output = drupal_get_form('Motos_dropdown_form', $form);
return $output;
function Motos_dropdown_form() {
$vid=7;
$formname="Motos - Quads";
$vocabulary = db_query("SELECT td.name, td.tid FROM {term_data} td WHERE td.vid=%d ORDER BY td.name", $vid);
// Initialise the country array
$options[] = t('' . $formname);
//Populate array with url / name
while ($term = db_fetch_object($vocabulary)) {
$options[url("taxonomy/term/$term->tid")] = $term->name;
}
//Build dropdown select
//If we try to build OnChange directly it gets mangled, so put in array to confuse the forms api
$form['category'] = array(
'#type' => 'select',
'#name' => $formname,
'#id' => $formname,
'#title' => '',
'#default_value' => '',
'#options' => $options,
'#description' => '',
'#multiple' => $multiple = FALSE,
'#required' => $required = FALSE,
'#attributes' => array('onChange' => "top.location.href=document.getElementById('$formname').options[document.getElementById('$formname').selectedIndex].value"),
);
return $form;
}
Comments
Why not just build one form
Why not just build one form with all the drop downs?
That's the idea but don't
That's the idea but don't know how to do that :-(
So in a single function add
So in a single function add all the code, one piece after another. The only two things you should need to change are
so that each of the five drop downs have different names (for example, cartegory1, category2, etc) and remove all but the last
return $form(You only want the one return at the end of the function). You will also want only one #form and #id value (you should not need to actually assign these, if you do make sure the #id is a valid css id (your current one is not)).Thanks for the reply, but
Thanks for the reply, but I'm not enough good on this:
:-(